<?php

$lines = file('id.txt', FILE_IGNORE_NEW_LINES);

$db = new SQLite3('citizens.db');

$db->exec('BEGIN');

foreach($lines as $line) {
	$a = explode(',', $line);
	$id = $a[0];
	
	$query = "SELECT citizen,residence FROM users WHERE id=$id ORDER BY residence";
					
	$result = $db->querySingle($query, TRUE);
	
	if ( !empty($result) && $result['citizen'] != 14 && $result['citizen'] != 81 && $result['residence'] != 14 )
		echo "$line, " . $result['residence'] . "\r\n";
}

$db->exec('COMMIT');

?>